import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
    int  _currentIndex = 0;
    PageController pageController = new PageController(initialPage: 0);

    void _onTapHandler(int index) {
//      pageController.animateToPage(index,
//          duration: Duration(milliseconds: 300), curve: Curves.ease);
    }

    List pages = ['aaaa','bbbbb','cccc','dddd'];
    void _onPageChanged(int index) {
      setState(() {
        _currentIndex = index;
      });
    }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView.builder(
          onPageChanged: _onPageChanged,
          itemCount:pages.length ,
          itemBuilder: (context,index) {
          return _itemWidget(index);
          },
        controller: pageController,
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: _onTapHandler,
        type: BottomNavigationBarType.fixed,
        fixedColor: Colors.grey,
        unselectedItemColor:Colors.purpleAccent,
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.card_giftcard),
            title: Text('页面1')
          ),
          BottomNavigationBarItem(
              icon: Icon(Icons.card_giftcard),
              title: Text('数据2')
          ),
          BottomNavigationBarItem(
              icon: Icon(Icons.card_giftcard),
              title: Text('案例3')
          ),
          BottomNavigationBarItem(
              icon: Icon(Icons.card_giftcard),
              title: Text('模板4')
          )
        ],
      ),
    );
  }

  Widget _itemWidget(index) {
    return Scaffold(
      appBar: AppBar(
        title: Text(index.toString()),
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            Text('页面${index.toString()}'),
            Text('数据${pages[index]}'),
          ],
        ),
      ),
    );


  }

}
